def dg(nums,depth,n,res,sum_cur):
    #递归出口
    if depth==n:
        res.append(sum_cur)
    for i in range(n-depth):
        if i==0 and i<n-depth-1:
            sum_cur+=nums[i]*nums[i+1]
            dg(nums[i+1:],depth+1,n,res,sum_cur)
            #回溯
            sum_cur-=nums[i]*nums[i+1]
        if i==0 and i==n-depth-1:
            sum_cur+=nums[i]
            dg(None,depth+1,n,res,sum_cur)
            sum_cur-=nums[i]
        if i>0 and i==n-depth-1:
            sum_cur+=nums[i]*nums[i-1]
            dg(nums[:i],depth+1,n,res,sum_cur)
            sum_cur-=nums[i]*nums[i-1]
        if i>0 and i<n-depth-1:
            sum_cur+=nums[i]*nums[i-1]*nums[i+1]
            dg(nums[:i]+nums[i+1:],depth+1,n,res,sum_cur)
            sum_cur-=nums[i]*nums[i-1]*nums[i+1]
def max_value(n,nums):
    #结果矩阵
    res=[]
    depth=0
    dg(nums,depth,n,res,0)
    # print(res)
    print(max(res))
# t=int(input())
# for i in range(t):
n=int(input())
nums=list(map(int,input().split()))
    # print(nums)

def maxValue(n,nums):

    pass
max_value(n,nums)


